<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<title>管理导航区域</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" href="css/common.css" type="text/css" />
		<link rel="stylesheet" href="css/jquery-ui-1.8.5.custom.css"
			type="text/css" />
		<script src="<%=basePath %>js/jquery-1.5.js" language="javascript">
</script>
		<script src="<%=basePath %>js/table.js" language="javascript">
</script>
		<script
			src="<%=basePath %>js/jquery-ui-1.8.5.custom.min.js"
			language="javascript">
		</script>
		<style>
.my-dialog .ui-dialog-titlebar-close {
	display: none;
}
</style>
<script src="js/ajaxfileupload.js" language="javascript">
</script>
		<script language="javascript">
function updatePayment() {
	var studentName = $("#stuName").val();
	var stuExamCode = $("#stuExamCode").val();
	var stuUnpaidFee = $("#stuUnpaidFee").val();
	var single = $("#singleImport").attr("checked");
	
	if (single) {
		if (studentName == "" || studentName == null) {
			alert("用户名不能为空");
			return;
		}
		if (stuExamCode == "" || stuExamCode == null) {
			alert("准考证号不能为空");
			return;
		}
		if (stuUnpaidFee == "" || stuUnpaidFee == null) {
			alert("欠费金额不能为空");
			return;
		}
		var param = {};
		param.stuName = studentName;
		param.examCode = stuExamCode;
		param.unpaidFees = stuUnpaidFee;
		
		
		$.post("json/adminExcel!updatePayment", param, function(data) {
			if (!data.result)
				alert("导入失败!学生姓名与准考证不对应或者欠费金额大于应交金额!!");
			else {
				alert("增加成功!")
				showAddStuPayment(data.result);
				updateResultIndex()
			}
		})
	} else {
		var file=$("#upload").attr("value");
				if(file==null || file==""){
					alert("请先选择上传的文件!");
					return;
				}
				var excel=file.substring(file.lastIndexOf(".")); 
				if(excel!=".xls" && excel!=".xlt"){
					alert("请上传'.xls格式的Excel文件!'");
					return;
				}
				
				$("#importErrorDiv").hide(); 
				$("#checkingImage").hide();//显示对与错的图片
				$("#checkingProgress").show();//显示处理进度条
				$("#importMessage").html("")
				//显示处理窗口
				$("#doLotImportDiv").show();
				$("#doLotImportDiv").dialog({
					modal: true,
					width:500,
					height:400,
					dialogClass: "my-dialog",
					buttons:{
						'完成':function(){
							$("#doLotImportDiv").dialog("close")
						}}
				})
				dlBtnEnable(false);
				//批量导入欠费信息
				 $.ajaxFileUpload({
                        url:'json/adminUploadExcel.action?flag=1', //你处理上传文件的服务端
                        secureuri:false,
                        fileElementId:'upload',
                        dataType: 'json',
                        success: function (data, status) {
					 		error=eval("("+data.error+")");
					 		if(error.length<=0){
					 			//没有错误
					 			$("#checkingImage").show();
					 			$("#checkingProgress").hide();
					 			$("#checkingImage").attr("src","images/right.png")
					 			$("#importMessage").html("<font size='+3' color='red'>导入成功</font>")
					 			var payments=eval("("+data.result+")");
					 			for(var i=0;i<payments.length;i++){
					 				showAddStuPayment(payments[i])
					 			}
					 			updateResultIndex()
					 			
					 		}else{
					 			
					 			 var table=$("#importErrorTable")
					 			 $("#importMessage").html("<font size='+3' color='red'>导入失败！</font>")
					 			 $("table#importErrorTable tr:gt(0)").remove();
                           		 for(var i=0;i<error.length;i++){	 
                                  	var tr='<tr><td align="center">'+(i+1)+'</td><td align="left" ><font color="red">'+error[i]+'</font></td></tr>';
                           		 	table.append($(tr));
                           		 }
                           		 	$("table#importErrorTable tr:gt(0):even").css('background','#deefff'); 
									$("table#importErrorTable tr:gt(0):odd").css('background','#fff');
									$("#checkingImage").attr("src","images/error.png")
									$("#checkingImage").show();
									$("#checkingProgress").hide();
									$("#importErrorDiv").show();
									
					 		}
					 		dlBtnEnable(true);
 
                        },
						error: function (data, status, e)
						{
							alert("上传失败！");
							$("#doLotImportDiv").dialog("close");
							dlBtnEnable(true);
						}
                   })
				
				//uploadDormExcel();
	}
}

function showAddStuPayment(stu) {
	$("#stuName").val("");
	$("#stuExamCode").val("");
	$("#stuUnpaidFee").val("");
	$("#stuPayList").show();
	if(typeof stu !='object')
		stu=eval("("+stu+")");		
	var name = stu.studentName;
	var examcode = stu.examCode;
	var unpaidFees = stu.unpaidFees;
	var feePayable=stu.feePayable
	var tr=	'<tr><td align="center" name="addRecodeIndex"></td><td align="center">'+name+'</td><td align="center"> '+examcode+'</td><td align="center">'+feePayable+'</td><td align="center"><font color="red">'+unpaidFees+'</font></td></tr>';
	$("#stuAddTable tr:eq(0)").after($(tr))
	$("table#stuAddTable tr:gt(0):even").css('background','#deefff'); 
	$("table#stuAddTable tr:gt(0):odd").css('background','#fff');
}
function updateResultIndex(){
	$("td[name='addRecodeIndex']").each(function(i,v){
		$(this).html(i+1)
	})
	
}
$(function(){
	/*	var stuList=[];
		
		if('${sessionScope.paymentList}'!=''){
		
			stuList='${sessionScope.paymentList}';
			stuList=eval("("+stuList+")");
		}
		for(var i=0;i<stuList.length;i++){
			showAddStuPayment(eval(stuList[i]));
		}
		updateResultIndex()*/
		$("#stuUnpaidFee").keyup(function(){//欠款金额限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})
		$("#stuExamCode").keyup(function(){//准考证 限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})
})

//上传学生表Excel
	function uploadPayExcel(){
		alert("up");
		var file=$("#upload").attr("value");
		if(file==null || file==""){
			alert("请选择上传的文件!");return;
		}
		var excel=file.substring(file.lastIndexOf(".")); 
		if(excel!=".xls" && excel!=".xlt"){
			alert("请上传'.xls格式的Excel文件!'");
			return;
		}
		$("#import_pay_excel_form").attr("action","adminUploadExcel.action?flag=1").submit();
		//$("#import_Dorm_excel_form");
	}
	
	function exportPayExcel() {
		
		$("#import_pay_excel_form").attr("action","exportPaymentExcelDemo.action").submit();
	}
		//控制按钮是否可用的函数.

function dlBtnEnable(enable)

{

    var dlgButton = $('.ui-dialog-buttonpane button');

    if (enable) {

        dlgButton.attr('disabled', '');

        dlgButton.removeClass('ui-state-disabled');

    } else {

        dlgButton.attr('disabled', 'disabled');

        dlgButton.addClass('ui-state-disabled');

    }

}
</script>
	</head>
	<body>
		<div class="adminhead">
			<jsp:include page="head.jsp"></jsp:include>
		</div>
		<div class="adminmain">
			<div class="left">
				<jsp:include page="leftMenu.jsp"></jsp:include>
			</div>
			<div class="right">
				<div id="nav">
			<ul>
				<li class="bg_image_onclick">
					导入缴费信息
				</li>
			</ul>
		</div>
		<div id="sub_info">
			&nbsp;&nbsp;
			<img src="images/hi.gif" />
			&nbsp;
			<span id="show_text">欢迎进入新生报告系统后台管理!</span>您现在正在：信息导入&gt;&gt;&gt;导入缴费信息
		</div>

		<div id="man_zone">
			<!--************************************************************-->
			<table width="700" border="0" align="center" cellpadding="1"
				cellspacing="5" height="70">
				<tr>
					<td width="74%">
						<div>
							<table width="100%" id="d1">
								<tr>
									<td width="15%" align="right">
										学生姓名：
									</td>
									<td width="18%">
										<input type="text" size="15" id="stuName" />
									</td>
									<td width="18%" align="right">
										准考证号：
									</td>
									<td width="49%">
										<input type="text" size="15" id="stuExamCode" />
									</td>
								</tr>
								<tr>
									<td align="right">
										未缴金额：
									</td>
									<td>
										<input type="text" size="15" id="stuUnpaidFee" />
									</td>
									<td align="right">
										&nbsp;
									</td>
									<td>
										&nbsp;
									</td>
								</tr>
							</table>

							<div id="d2" style="display: none; padding-left: 20px;">
								<form action="" id="import_pay_excel_form" method="post"
									enctype="multipart/form-data">
									<input type="file" name="upload" id="upload" />
									&nbsp;&nbsp;
									<input type="button" value="下载模板" onclick="exportPayExcel()" />
								</form>
								<font color="red">请选择下载模版,填写内容后再导入</font>
							</div>

						</div>
					</td>
					<td width="19%" style="border-left: 1px dotted red;">
						<div>
							<input name="a" type="radio" value="" checked="checked"
								id="singleImport"
								onclick="document.getElementById('d1').style.display='block';document.getElementById('d2').style.display='none';" />
							单个导入
						</div>
						<div>
							<input name="a" type="radio" value=""
								onclick="document.getElementById('d1').style.display='none';document.getElementById('d2').style.display='block';" />
							批量导入
						</div>
					</td>
					<td width="7%">
						<input type="button" value="执行" onclick="updatePayment()" />
					</td>
				</tr>
			</table>
			<!--************************************************************-->
			<div id="stuPayList" style="display: none">
				<h2 style="text-align: center; color: red;">
					更新欠费记录
				</h2>
				<table width="950" height="31" border="0" align="center"
					cellpadding="0" cellspacing="1" class="t1"
					style="margin-top: 20px; border: 1px solid #5cb0ff;"
					id="stuAddTable">
					<tr style="color: #000;">
						<th height="20" align="center">
							序号
						</th>
						<th height="20" align="center">
							姓名
						</th>
						<th height="20" align="center">
							准考证号
						</th>
						<th height="20" align="center">
							学费
						</th>
						<th height="20" align="center">
							欠费金额
						</th>
					</tr>
				</table>
			</div>

			<!--************************************************************-->
		</div>
		<!--                   批量导入时的弹出div -->
		<div id="doLotImportDiv" title="批量导入欠费信息" style="display: none">
			<table width="100%">
				<tr>
					<td align="left">
						<font color="red" size="2px">正在导入。。。</font>
						<br />
					</td>
					<td align="right">
						<img src="images/right.png" alt="" width="30px" id="checkingImage" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<img src="images/progressBar.gif" alt="正在导入。。。"
							id="checkingProgress" />
						<div id="importMessage">

						</div>
					</td>
				</tr>
				<tr>
					<td>

						<div id="importErrorDiv" style="display: none">
							<table id="importErrorTable" width="100%" border="0" style=""
								class="t1">
								<tr style="font-size: 18px; font-weight: bold; color: red">
									<th width="10%" align="center">
										序号
									</th>
									<th align="center">
										错误信息
									</th>
									<tr>
										<tr>
											<td align="center">
												1
											</td>
											<td align="center">
												宿舍号重复
											</td>
										</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
			<div>


			</div>
		</div>
		
			</div>
		</div>
		<div class="adminfooter">
			<jsp:include page="footer.jsp"></jsp:include>
		</div>
		
	</body>
</html>
